package demo3;

public class test {
    public static void main(String[] args) {
        Object loker1=new Object();
        Object loker2=new Object();

        Thread t1=new Thread(()->{
            synchronized (loker1){
                try {
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
                synchronized (loker2){
                    System.out.println("t1加锁成功");
                }
            }
        });
        Thread t2=new Thread(()->{
            synchronized (loker2){
                try {
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
                synchronized (loker1){
                    System.out.println("t2加锁成功");
                }
            }
        });
t1.start();
t2.start();


    }
}
